﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Character;
using UnityEngine;

/// <summary>全局数据</summary>
public static class GlobalData
{
	public static readonly string directory = Application.dataPath + "/../UserData/Save";
	public static readonly string file = Application.dataPath + "/../UserData/Save/SystemData";
	public static readonly string assetBundlePath = Application.dataPath + "/../abdata";
	public static readonly int version = 12;
	public static int sortChara = 0;
	public static int sortCoord = 0;
	public static bool poseChangeCameraFocus = false;
	public static int continueSaveNo = -1;
	public static bool flipflop = false;
	public static bool vr_event_item = false;
	public static bool showUploaderRule = false;
	public static string uploaderHandleName = string.Empty;
	public static MALE_SHOW[] maleShows = new MALE_SHOW[5];
	public static bool showMap = true;
	public static bool isMemory = false;
	private static Dictionary<int, MapAssetBundleInfo> _mapABTable = new Dictionary<int, MapAssetBundleInfo>();
	public static GamePlayData PlayData = null;

	// Token: 0x06001343 RID: 4931 RVA: 0x0008A6B4 File Offset: 0x000888B4
	public static void Save()
	{
		if (!Directory.Exists(GlobalData.directory))
		{
			Directory.CreateDirectory(GlobalData.directory);
		}
		FileStream fileStream = new FileStream(GlobalData.file, FileMode.Create);
		BinaryWriter binaryWriter = new BinaryWriter(fileStream);
		binaryWriter.Write(GlobalData.version);
		binaryWriter.Write(GlobalData.sortChara);
		binaryWriter.Write(GlobalData.sortCoord);
		binaryWriter.Write(GlobalData.poseChangeCameraFocus);
		binaryWriter.Write(GlobalData.continueSaveNo);
		binaryWriter.Write(GlobalData.flipflop);
		binaryWriter.Write(GlobalData.vr_event_item);
		binaryWriter.Write(GlobalData.showUploaderRule);
		binaryWriter.Write(GlobalData.uploaderHandleName);
		for (int i = 0; i < GlobalData.maleShows.Length; i++)
		{
			binaryWriter.Write((int)GlobalData.maleShows[i]);
		}
		binaryWriter.Close();
		fileStream.Close();
	}

	// Token: 0x06001344 RID: 4932 RVA: 0x0008A784 File Offset: 0x00088984
	public static void Load()
	{
		if (!File.Exists(GlobalData.file)) return;
		FileStream fileStream = new FileStream(GlobalData.file, FileMode.Open);
		if (fileStream == null) return;
		BinaryReader binaryReader = new BinaryReader(fileStream);
		int num = binaryReader.ReadInt32();
		if (num < 0 || num > GlobalData.version)
		{
			GlobalData.Debug_LogError("不明版本：" + num);
			binaryReader.Close();
			fileStream.Close();
			return;
		}
		if (num < 7)
		{
			binaryReader.Close();
			fileStream.Close();
			return;
		}
		GlobalData.sortChara = binaryReader.ReadInt32();
		GlobalData.sortCoord = binaryReader.ReadInt32();
		GlobalData.poseChangeCameraFocus = binaryReader.ReadBoolean();
		if (num >= 8)
		{
			GlobalData.continueSaveNo = binaryReader.ReadInt32();
		}
		if (num >= 9)
		{
			GlobalData.flipflop = binaryReader.ReadBoolean();
			GlobalData.vr_event_item = binaryReader.ReadBoolean();
		}
		if (num >= 10)
		{
			GlobalData.showUploaderRule = binaryReader.ReadBoolean();
		}
		if (num >= 11)
		{
			GlobalData.uploaderHandleName = binaryReader.ReadString();
		}
		if (num >= 12)
		{
			for (int i = 0; i < GlobalData.maleShows.Length; i++)
			{
				GlobalData.maleShows[i] = (MALE_SHOW)binaryReader.ReadInt32();
			}
		}
		else
		{
			for (int j = 0; j < GlobalData.maleShows.Length; j++)
			{
				GlobalData.maleShows[j] = MALE_SHOW.CLOTHING;
			}
		}
		binaryReader.Close();
		fileStream.Close();
	}

	// Token: 0x06001345 RID: 4933 RVA: 0x0008A8E4 File Offset: 0x00088AE4
	public static bool CheckContinueSave()
	{
		if (GlobalData.continueSaveNo != -1)
		{
			string continueSaveFile = GlobalData.GetContinueSaveFile();
			return File.Exists(continueSaveFile);
		}
		return false;
	}

	// Token: 0x06001346 RID: 4934 RVA: 0x0008A90C File Offset: 0x00088B0C
	public static string GetContinueSaveFile()
	{
		return Directory.GetCurrentDirectory() + "/UserData/save/Game/" + (GlobalData.continueSaveNo + 1).ToString("00") + ".gsd";
	}

	// Token: 0x06001347 RID: 4935 RVA: 0x0008A944 File Offset: 0x00088B44
	public static void CheckMapNames()
	{
		GlobalData._mapABTable.Clear();
		List<string> list = Directory.GetFiles(GlobalData.assetBundlePath + "/map", "maplist_*", SearchOption.TopDirectoryOnly).ToList<string>();
		for (int i = 0; i < list.Count; i++)
		{
			string path = list[i];
			if (!Path.HasExtension(path))
			{
				string directoryName = Path.GetDirectoryName(path);
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
				ExcelData excelData = AssetBundleLoader.LoadAsset<ExcelData>(directoryName, fileNameWithoutExtension, fileNameWithoutExtension);
				if (!(excelData == null))
				{
					for (int j = 0; j < excelData.MaxCell; j++)
					{
						List<string> row = excelData.GetRow(j);
						int num = 0;
						int key;
						if (int.TryParse(row.ElementAtOrDefault(num++), out key))
						{
							string name = row.ElementAtOrDefault(num++);
							string assetBundleName = row.ElementAtOrDefault(num++);
							string assetName = row.ElementAtOrDefault(num++);
							string assetBundleManifestName = row.ElementAtOrDefault(num++);
							MapAssetBundleInfo mapAssetBundleInfo;
							if (!GlobalData._mapABTable.TryGetValue(key, out mapAssetBundleInfo))
							{
								MapAssetBundleInfo mapAssetBundleInfo2 = new MapAssetBundleInfo
								{
									AssetBundleInfo = new AssetBundleInfo()
								};
								GlobalData._mapABTable[key] = mapAssetBundleInfo2;
								mapAssetBundleInfo = mapAssetBundleInfo2;
							}
							mapAssetBundleInfo.Name = name;
							mapAssetBundleInfo.AssetBundleInfo.AssetBundleName = assetBundleName;
							mapAssetBundleInfo.AssetBundleInfo.AssetName = assetName;
							mapAssetBundleInfo.AssetBundleInfo.AssetBundleManifestName = assetBundleManifestName;
						}
					}
				}
			}
		}
	}

	// Token: 0x06001348 RID: 4936 RVA: 0x0008AACC File Offset: 0x00088CCC
	public static int GetMapNum()
	{
		return GlobalData._mapABTable.Count;
	}

	// Token: 0x06001349 RID: 4937 RVA: 0x0008AAD8 File Offset: 0x00088CD8
	public static string GetMapShowName(int mapNo)
	{
		MapAssetBundleInfo mapAssetBundleInfo;
		if (!GlobalData._mapABTable.TryGetValue(mapNo, out mapAssetBundleInfo))
		{
			return string.Empty;
		}
		return mapAssetBundleInfo.Name;
	}

	// Token: 0x0600134A RID: 4938 RVA: 0x0008AB04 File Offset: 0x00088D04
	public static string GetMapAssetBundleName(int mapNo)
	{
		MapAssetBundleInfo mapAssetBundleInfo;
		if (!GlobalData._mapABTable.TryGetValue(mapNo, out mapAssetBundleInfo))
		{
			return string.Empty;
		}
		return mapAssetBundleInfo.AssetBundleInfo.AssetBundleName;
	}

	// Token: 0x0600134B RID: 4939 RVA: 0x0008AB34 File Offset: 0x00088D34
	public static string GetMapAssetName(int mapNo)
	{
		MapAssetBundleInfo mapAssetBundleInfo;
		if (!GlobalData._mapABTable.TryGetValue(mapNo, out mapAssetBundleInfo))
		{
			return string.Empty;
		}
		return mapAssetBundleInfo.AssetBundleInfo.AssetName;
	}

	// Token: 0x0600134C RID: 4940 RVA: 0x0008AB64 File Offset: 0x00088D64
	public static string GetMapManifestName(int mapNo)
	{
		MapAssetBundleInfo mapAssetBundleInfo;
		if (!GlobalData._mapABTable.TryGetValue(mapNo, out mapAssetBundleInfo))
		{
			return string.Empty;
		}
		return mapAssetBundleInfo.AssetBundleInfo.AssetBundleManifestName;
	}

	/// <summary>日志</summary>
	public static void Debug_Log(string str)
    {
		Debug.Log(str);
	}
	public static void Debug_Log(object str)
	{
		Debug.Log(str);
	}
	public static void Debug_Log(string str, UnityEngine.Object objstr)
	{
		Debug.Log(str, objstr);
	}
	/// <summary>日志 警告</summary>
	public static void Debug_LogWarning(string str)
	{
		Debug.LogWarning(str);
	}
	public static void Debug_LogWarning(object str)
	{
		Debug.LogWarning(str);
	}
	public static void Debug_LogError(string str)
	{
		Debug.LogError(str);
	}
	public static void Debug_LogError(object str)
	{
		Debug.LogError(str);
	}
	public static void Debug_LogError(string str, UnityEngine.Object objstr)
	{
		Debug.LogError(str, objstr);
	}
}
